'''
优点：
    1）对唯一实例的受控访问
    2）单例相当于全局变量，但防止了命名空间被污染
'''

class Singleton:
    def __new__(cls,*args,**kwargs):
        if not hasattr(cls,'_instance'):
            cls._instance = super(Singleton,cls).__new__(cls)
        return cls._instance

class MyClass(Singleton):
    def __init__(self,a) -> None:
        self.a = a


if __name__ == '__main__':
    a = MyClass(10)
    b = MyClass(20)
    print(id(a),id(b))

    